package com.niit;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;

import com.niit.common.pojo.ApiResponse;
import com.niit.common.pojo.ApiResponseEnum;
import com.niit.common.util.ConstatFinalUtil;
import com.niit.users.action.BusAction;
import com.niit.users.action.NoLoginAction;
import com.niit.users.action.UsersAction;
import com.niit.users.pojo.TbBus;
import com.niit.users.pojo.TbBusTimeable;
import com.niit.users.pojo.TbMananger;
import com.niit.users.pojo.TbOrder;
import com.niit.users.pojo.TbOrderEnum;
import com.niit.users.pojo.TbPassenger;

import lombok.extern.log4j.Log4j2;

/**
 * 代码包结构： action ：写界面操作 service: 业务层 dao: 数据库交互，jdbc pojo: 实体映射
 * 
 *
 */
@Log4j2
public class MainAction {
    private NoLoginAction loginAction = new NoLoginAction();
    private BusAction busAction = new BusAction();
    private UsersAction usersAction = new UsersAction();

    public static void main(String[] args) {
        MainAction mainAction = new MainAction();
        Scanner scanner = new Scanner(System.in);
        /* 选择用户类型 */
        String line = "";
        while (true) {
            mainAction.menWelcome();
            line = scanner.nextLine();
            line = line.trim();
            if ("0".equalsIgnoreCase(line)) {
                /* 管理员操作 */
                mainAction.menUnAdmins(scanner);
            } else if ("1".equalsIgnoreCase(line)) {
                /* 乘客操作 */
                mainAction.menUnPass(scanner);
            } else if ("N".equalsIgnoreCase(line)) {
                break;
            } else {
                System.out.println("==您的输入有误,请重新输入==");
            }
        }
        System.out.println("==欢迎下次使用==");
    }

    /**
     * 欢迎页面菜单
     */
    private void menWelcome() {
        System.out.println("---------------------");
        System.out.println("--- 欢迎使用 巴士订票系统(按N退出系統) ---");
        System.out.println("---------------------");
        System.out.println("--- 请选择用户类型(0:管理员;1:乘客) ---");
    }

    /**
     * 管理员(菜单)
     */
    private void menLoginSuccessAdmins(Scanner scanner) {
        while (true) {
            System.out.println("---------------------");
            System.out.println("--- 管理员菜单 ---");
            System.out.println("--- 1.管理巴士信息 ---");
            System.out.println("--- 2.管理乘客信息 ---");
            System.out.println("--- 3.管理班次信息 ---");
            System.out.println("--- 4.售票 ---");
            System.out.println("--- 5.退票 ---");
            System.out.println("--- 6.查询用户订单 ---");
            System.out.println("--- b.返回上一级 ---");

            String line = scanner.nextLine();
            line = line.trim();
            try {
                if ("1".equalsIgnoreCase(line)) {
                    busManager(scanner);
                } else if ("2".equalsIgnoreCase(line)) {
                    usersManager(scanner);
                } else if ("3".equalsIgnoreCase(line)) {
                    busTimeableManager(scanner);
                } else if ("4".equalsIgnoreCase(line)) {
                    orderSale(scanner, "");
                } else if ("5".equalsIgnoreCase(line)) {
                    orderRefunded(scanner);
                } else if ("6".equalsIgnoreCase(line)) {
                    orderManager(scanner, "");
                } else if ("b".equalsIgnoreCase(line)) {
                    break;
                }
            } catch (Exception e) {
                log.error("操作数据有误,您输入的是:{}", line, e);
            }
        }
    }

    /**
     * 退票
     * @param scanner
     */
    private void orderRefunded(Scanner scanner) {
        String line = "";
        /* 更新 */
        System.out.println("--- 请输入订单信息(查看):(格式为:订单Id) ---");
        line = scanner.nextLine();
        line = line.trim();
        Map<String, Object> condMap = new HashMap<String, Object>();
        condMap.put("id", line);
        ApiResponse<TbOrder> apiResponseDb = this.busAction.findOneOrderService(condMap);
        TbOrder dbObj = apiResponseDb.getDataOneJava();
        if (Objects.nonNull(dbObj)) {
            /* 回显信息 */
            dbObj.printInput();
            System.out.println("--- 是否要退票:y(是),n(否) ---");
            line = scanner.nextLine();
            line = line.trim();
            if ("y".equalsIgnoreCase(line)) {
                dbObj.setOrderStatus(TbOrderEnum.ORDERSTATUS_REFUNDED.getStatus());
                ApiResponse<Object> dbApiResponseInfo = this.busAction.updateOneOrderService(dbObj);
                System.out.println("==更新班次操作;信息:==" + dbApiResponseInfo.getInfo());
            }else if ("n".equalsIgnoreCase(line)) {
                System.out.println("==您选择了否(不退票):==");
            } else {
                System.out.println("--- 您输入有误 ---");
            }
        } else {
            System.out.println(ApiResponseEnum.INFO_RECORD_NOT_EXISTS.getName());
        }
    }

    /**
     * 售票
     * @param scanner
     */
    private void orderSale(Scanner scanner, String passagerId) {
        String line = "";
        /* 查询巴士信息，班次信息 */
        Map<String,Object> paramsMap = new HashMap<String, Object>();
        this.busAction.findCondListBusService(null, paramsMap);
        this.busAction.findCondListBusTimeableService(null, paramsMap);
        /* 添加 */
        System.out.println("--- 请输入订单信息;(格式为:乘客Id;巴士Id;班次Id;乘车日期;座位号; ---");
        if (passagerId != null && !"".equalsIgnoreCase(passagerId)) {
            System.out.println("当前为乘客登记,乘客id为:==" + passagerId);
        }
        line = scanner.nextLine();
        line = line.trim();
        String[] splitArr = line.split(ConstatFinalUtil.SPLIT_INPUT_STR);
        if (Objects.nonNull(splitArr) && splitArr.length == 5) {
            TbOrder pojo = new TbOrder();
            if (passagerId == null || "".equalsIgnoreCase(passagerId)) {
                passagerId = splitArr[0];
            }
            pojo.setPassengerId(Integer.parseInt(passagerId));
            pojo.setBusId(Integer.parseInt(splitArr[1]));
            pojo.setTimetableId(Integer.parseInt(splitArr[2]));
            pojo.setRideDate(splitArr[3]);
            pojo.setSeatNo(Integer.parseInt(splitArr[4]));
            System.out.println("--- 是否要支付:y(是),n(否) ---");
            line = scanner.nextLine();
            line = line.trim();
            if ("y".equalsIgnoreCase(line)) {
                pojo.setOrderStatus(TbOrderEnum.ORDERSTATUS_PAYED.getStatus());
                
                ApiResponse<Object> dbApiResponseInfo = this.busAction.saveOneOrderService(pojo);
                System.out.println("==保存班次操作;信息:==" + dbApiResponseInfo.getInfo());
            }else if ("n".equalsIgnoreCase(line)) {
                System.out.println("==您选择了否(不退票):==");
                
                ApiResponse<Object> dbApiResponseInfo = this.busAction.saveOneOrderService(pojo);
                System.out.println("==保存班次操作;信息:==" + dbApiResponseInfo.getInfo());
            } else {
                System.out.println("--- 您输入有误 ---");
            }
        } else {
            System.out.println("--- 您输入数量不正确 ---");
        }
    }

    /**
     * 用户订单
     * 
     * @param scanner
     */
    private void orderManager(Scanner scanner, String passengerId) {
        System.out.println("--- 订单信息如下 ---");
        Map<String, Object> condMap = new HashMap<String, Object>();
        condMap.put("passengerId", passengerId);
        this.busAction.findCondListOrderService(null, condMap);
    }

    /**
     * 管理班次信息
     * 
     * @param scanner
     */
    private void busTimeableManager(Scanner scanner) {
        while (true) {
            System.out.println("---------------------");
            System.out.println("--- 管理员菜单(管理班次信息) ---");
            System.out.println("--- 1.查询列表 ---");
            System.out.println("--- 2.添加 ---");
            System.out.println("--- 3.更新 ---");
            System.out.println("--- 4.删除 ---");
            System.out.println("--- b.返回上一级 ---");

            String line = scanner.nextLine();
            line = line.trim();
            try {
                if ("1".equalsIgnoreCase(line)) {
                    Map<String, Object> condMap = new HashMap<String, Object>();
                    this.busAction.findCondListBusTimeableService(null, condMap);
                } else if ("2".equalsIgnoreCase(line)) {
                    /* 添加 */
                    System.out.println("--- 请输入班次信息;(格式为:巴士Id;起始站;发车时间;经停站;终点站;抵达终点时间;票价) ---");
                    line = scanner.nextLine();
                    line = line.trim();
                    String[] splitArr = line.split(ConstatFinalUtil.SPLIT_INPUT_STR);
                    if (Objects.nonNull(splitArr) && splitArr.length == 7) {
                        TbBusTimeable mananger = new TbBusTimeable();
                        mananger.setBusId(Integer.parseInt(splitArr[0]));
                        mananger.setDepartureStation(splitArr[1]);
                        mananger.setDepartureTime(splitArr[2]);
                        mananger.setPassStation(splitArr[3]);
                        mananger.setTerminalStation(splitArr[4]);
                        mananger.setArrivalTime(splitArr[5]);
                        mananger.setTicketRate(Float.parseFloat(splitArr[6]));
                        ApiResponse<Object> dbApiResponseInfo = this.busAction.saveOneBusTimeableService(mananger);
                        System.out.println("==保存班次操作;信息:==" + dbApiResponseInfo.getInfo());
                    } else {
                        System.out.println("--- 您输入数量不正确 ---");
                    }
                } else if ("3".equalsIgnoreCase(line)) {
                    /* 更新 */
                    System.out.println("--- 请输入班次信息(查看):(格式为:班次Id) ---");
                    line = scanner.nextLine();
                    line = line.trim();
                    Map<String, Object> condMap = new HashMap<String, Object>();
                    condMap.put("id", line);
                    ApiResponse<TbBusTimeable> apiResponseDb = this.busAction.findOneBusTimeableService(condMap);
                    TbBusTimeable dbObj = apiResponseDb.getDataOneJava();
                    if (Objects.nonNull(dbObj)) {
                        /* 回显信息 */
                        dbObj.printInput();
                        System.out.println("--- 请输入班次信息(更新):(格式为:巴士Id;起始站;发车时间;经停站;终点站;抵达终点时间;票价) ---");
                        line = scanner.nextLine();
                        line = line.trim();
                        String[] splitArr = line.split(ConstatFinalUtil.SPLIT_INPUT_STR);
                        if (Objects.nonNull(splitArr) && splitArr.length == 7) {
                            dbObj.setBusId(Integer.parseInt(splitArr[0]));
                            dbObj.setDepartureStation(splitArr[1]);
                            dbObj.setDepartureTime(splitArr[2]);
                            dbObj.setPassStation(splitArr[4]);
                            dbObj.setTerminalStation(splitArr[3]);
                            dbObj.setArrivalTime(splitArr[5]);
                            dbObj.setTicketRate(Float.parseFloat(splitArr[6]));
                            ApiResponse<Object> dbApiResponseInfo = this.busAction.updateOneBusTimeableService(dbObj);
                            System.out.println("==更新巴士操作;信息:==" + dbApiResponseInfo.getInfo());
                        } else {
                            System.out.println("--- 您输入数量不正确 ---");
                        }
                    } else {
                        System.out.println(ApiResponseEnum.INFO_RECORD_NOT_EXISTS.getName());
                    }
                } else if ("4".equalsIgnoreCase(line)) {
                    /* 更新 */
                    System.out.println("--- 请输入班次信息(删除):(请输入班次Id) ---");
                    line = scanner.nextLine();
                    line = line.trim();
                    Map<String, Object> condMap = new HashMap<String, Object>();
                    condMap.put("id", line);
                    this.busAction.deleteOneBusTimeableService(condMap);
                } else if ("b".equalsIgnoreCase(line)) {
                    break;
                }
            } catch (Exception e) {
                log.error("操作数据有误,您输入的是:{}", line, e);
            }
        }
    }

    /**
     * 管理用户信息
     */
    private void usersManager(Scanner scanner) {
        while (true) {
            System.out.println("---------------------");
            System.out.println("--- 管理员菜单(管理乘客信息) ---");
            System.out.println("--- 1.查询列表 ---");
            System.out.println("--- 2.添加 ---");
            System.out.println("--- 3.更新 ---");
            System.out.println("--- 4.删除 ---");
            System.out.println("--- b.返回上一级 ---");

            String line = scanner.nextLine();
            line = line.trim();
            try {
                if ("1".equalsIgnoreCase(line)) {
                    Map<String, Object> condMap = new HashMap<String, Object>();
                    this.usersAction.findCondListPassengerService(null, condMap);
                } else if ("2".equalsIgnoreCase(line)) {
                    TbPassenger passUtil = new TbPassenger();
                    /* 添加 */
                    System.out.println("--- 请输入乘客信息;(格式如下) ---");
                    passUtil.printInputTitle();
                    
                    line = scanner.nextLine();
                    line = line.trim();
                    String[] splitArr = line.split(ConstatFinalUtil.SPLIT_INPUT_STR);
                    if (Objects.nonNull(splitArr) && splitArr.length == 5) {
                        TbPassenger mananger = new TbPassenger();
                        mananger.setPassengerIdCardNo(splitArr[0]);
                        mananger.setPassengerPasswd(splitArr[1]);
                        mananger.setPassengerName(splitArr[2]);
                        mananger.setPassengerPhoneNo(splitArr[3]);
                        mananger.setPassengerGender(Integer.parseInt(splitArr[4]));
                        ApiResponse<Object> dbApiResponseInfo = this.usersAction.saveOnePassengerService(mananger);
                        System.out.println("==保存乘客操作;信息:==" + dbApiResponseInfo.getInfo());
                    } else {
                        System.out.println("--- 您输入数量不正确 ---");
                    }
                } else if ("3".equalsIgnoreCase(line)) {
                    /* 更新 */
                    System.out.println("--- 请输入乘客信息(查看):(格式为:乘客Id) ---");
                    line = scanner.nextLine();
                    line = line.trim();
                    Map<String, Object> condMap = new HashMap<String, Object>();
                    condMap.put("id", line);
                    ApiResponse<TbPassenger> apiResponseDb = this.usersAction.findOnePassengerService(condMap);
                    TbPassenger dbObj = apiResponseDb.getDataOneJava();
                    if (Objects.nonNull(dbObj)) {
                        /* 回显信息 */
                        dbObj.printInput();
                        System.out.println("--- 请输入乘客信息(更新):(格式如下) ---");
                        dbObj.printInputTitle();
                        line = scanner.nextLine();
                        line = line.trim();
                        String[] splitArr = line.split(ConstatFinalUtil.SPLIT_INPUT_STR);
                        if (Objects.nonNull(splitArr) && splitArr.length == 5) {
                            TbPassenger mananger = apiResponseDb.getDataOneJava();
                            if (Objects.nonNull(mananger)) {
                                mananger.setPassengerIdCardNo(splitArr[0]);
                                mananger.setPassengerPasswd(splitArr[1]);
                                mananger.setPassengerName(splitArr[2]);
                                mananger.setPassengerPhoneNo(splitArr[3]);
                                mananger.setPassengerGender(Integer.parseInt(splitArr[4]));
                                ApiResponse<Object> dbApiResponseInfo = this.usersAction.updateOnePassengerService(mananger);
                                System.out.println("==更新乘客操作;信息:==" + dbApiResponseInfo.getInfo());
                            } else {
                                System.out.println("==记录不存在==");
                            }
                        } else {
                            System.out.println("--- 您输入数量不正确 ---");
                        }
                    } else {
                        System.out.println(ApiResponseEnum.INFO_RECORD_NOT_EXISTS.getName());
                    }
                } else if ("4".equalsIgnoreCase(line)) {
                    /* 删除 */
                    System.out.println("--- 请输入乘客信息(删除):(请输入乘客Id) ---");
                    line = scanner.nextLine();
                    line = line.trim();
                    Map<String, Object> condMap = new HashMap<String, Object>();
                    condMap.put("id", line);
                    this.usersAction.deleteOnePassengerService(condMap);
                } else if ("b".equalsIgnoreCase(line)) {
                    break;
                }
            } catch (Exception e) {
                log.error("操作数据有误,您输入的是:{}", line, e);
            }
        }
    }

    /**
     * 管理巴士信息
     * 
     * @param scanner
     */
    private void busManager(Scanner scanner) {
        while (true) {
            System.out.println("---------------------");
            System.out.println("--- 管理员菜单(管理巴士信息) ---");
            System.out.println("--- 1.查询列表 ---");
            System.out.println("--- 2.添加 ---");
            System.out.println("--- 3.更新 ---");
            System.out.println("--- 4.删除 ---");
            System.out.println("--- b.返回上一级 ---");

            String line = scanner.nextLine();
            line = line.trim();
            try {
                if ("1".equalsIgnoreCase(line)) {
                    Map<String, Object> condMap = new HashMap<String, Object>();
                    this.busAction.findCondListBusService(null, condMap);
                } else if ("2".equalsIgnoreCase(line)) {
                    /* 添加 */
                    System.out.println("--- 请输入巴士信息;(格式为:车牌号;座位数) ---");
                    line = scanner.nextLine();
                    line = line.trim();
                    String[] splitArr = line.split(ConstatFinalUtil.SPLIT_INPUT_STR);
                    if (Objects.nonNull(splitArr) && splitArr.length == 2) {
                        TbBus mananger = new TbBus();
                        mananger.setBusLicenseNo(splitArr[0]);
                        mananger.setBusSeating(Integer.parseInt(splitArr[1]));
                        ApiResponse<Object> dbApiResponseInfo = this.busAction.saveOneBusService(mananger);
                        System.out.println("==保存巴士操作;信息:==" + dbApiResponseInfo.getInfo());
                    } else {
                        System.out.println("--- 您输入数量不正确 ---");
                    }
                } else if ("3".equalsIgnoreCase(line)) {
                    /* 更新 */
                    System.out.println("--- 请输入巴士信息(查看):(格式为:巴士Id) ---");
                    line = scanner.nextLine();
                    line = line.trim();
                    Map<String, Object> condMap = new HashMap<String, Object>();
                    condMap.put("id", line);
                    ApiResponse<TbBus> apiResponseDb = this.busAction.findOneBusService(condMap);
                    TbBus dbObj = apiResponseDb.getDataOneJava();
                    if (Objects.nonNull(dbObj)) {
                        /* 回显信息 */
                        dbObj.printInput();
                        System.out.println("--- 请输入巴士信息(更新):(格式为:车牌号;座位数) ---");
                        line = scanner.nextLine();
                        line = line.trim();
                        String[] splitArr = line.split(ConstatFinalUtil.SPLIT_INPUT_STR);
                        if (Objects.nonNull(splitArr) && splitArr.length == 2) {
                            TbBus mananger = apiResponseDb.getDataOneJava();
                            if (Objects.nonNull(mananger)) {
                                mananger.setBusId(dbObj.getBusId());
                                mananger.setBusLicenseNo(splitArr[0]);
                                mananger.setBusSeating(Integer.parseInt(splitArr[1]));
                                ApiResponse<Object> dbApiResponseInfo = this.busAction.updateOneBusService(mananger);
                                System.out.println("==更新巴士操作;信息:==" + dbApiResponseInfo.getInfo());
                            } else {
                                System.out.println("==记录不存在==");
                            }
                        } else {
                            System.out.println("--- 您输入数量不正确 ---");
                        }
                    } else {
                        System.out.println(ApiResponseEnum.INFO_RECORD_NOT_EXISTS.getName());
                    }
                } else if ("4".equalsIgnoreCase(line)) {
                    /* 删除 */
                    System.out.println("--- 请输入巴士信息(删除):(请输入巴士Id) ---");
                    line = scanner.nextLine();
                    line = line.trim();
                    Map<String, Object> condMap = new HashMap<String, Object>();
                    condMap.put("id", line);
                    this.busAction.deleteOneBusService(condMap);
                } else if ("b".equalsIgnoreCase(line)) {
                    break;
                }
            } catch (Exception e) {
                log.error("操作数据有误,您输入的是:{}", line, e);
            }
        }
    }

    /**
     * 管理员(菜单)
     */
    private void menUnAdmins(Scanner scanner) {
        while (true) {
            System.out.println("---------------------");
            System.out.println("--- 管理员未登录 ---");
            System.out.println("--- 1.登录 ---");
            System.out.println("--- 2.注册 ---");
            System.out.println("--- b.返回上一步 ---");

            String line = scanner.nextLine();
            line = line.trim();
            try {
                if ("1".equalsIgnoreCase(line)) {
                    /* 登录 */
                    System.out.println("--- 请输入用户名和密码;(格式为:用户名;密码) ---");
                    line = scanner.nextLine();
                    line = line.trim();
                    String[] splitArr = line.split(ConstatFinalUtil.SPLIT_INPUT_STR);
                    if (Objects.nonNull(splitArr) && splitArr.length == 2) {
                        TbMananger mananger = new TbMananger();
                        mananger.setManangerName(splitArr[0]);
                        mananger.setManagerPasswd(splitArr[1]);
                        ApiResponse<Object> dbApiResponseInfo = this.loginAction.adminsLogin(mananger);
                        System.out.println("==登录操作;信息:==" + dbApiResponseInfo.getInfo());
                        if (dbApiResponseInfo.getCode() == ApiResponseEnum.INFO_LOGIN_SUCCES.getStatus()) {
                            /* 跳转到登录成功的菜单 */
                            menLoginSuccessAdmins(scanner);
                        }
                    } else {
                        System.out.println("--- 您输入数量不正确 ---");
                    }
                } else if ("2".equalsIgnoreCase(line)) {
                    /* 注册 */
                    System.out.println("--- 请输入用户名和密码;(格式为:用户名;密码;手机号) ---");
                    line = scanner.nextLine();
                    line = line.trim();
                    String[] splitArr = line.split(ConstatFinalUtil.SPLIT_INPUT_STR);
                    if (Objects.nonNull(splitArr) && splitArr.length == 3) {
                        TbMananger mananger = new TbMananger();
                        mananger.setManangerName(splitArr[0]);
                        mananger.setManagerPasswd(splitArr[1]);
                        mananger.setManagerPhoneNo(splitArr[2]);
                        ApiResponse<Object> dbApiResponseInfo = this.loginAction.adminsRegister(mananger);
                        System.out.println("==注册操作;信息:==" + dbApiResponseInfo.getInfo());
                    } else {
                        System.out.println("--- 您输入数量不正确 ---");
                    }
                } else if ("b".equalsIgnoreCase(line)) {
                    break;
                }
            } catch (Exception e) {
                log.error("操作数据有误,您输入的是:{}", line, e);
            }
        }
    }

    /**
     * 乘客(菜单)
     */
    private void menLoginSuccessPass(Scanner scanner) {
        TbPassenger passenger = (TbPassenger) ConstatFinalUtil.SYS_PRO_MAP.get("users");
        while (true) {
            System.out.println("---------------------");
            System.out.println("--- 乘客菜单 ---");
            System.out.println("--- 1.购票 ---");
            System.out.println("--- 2.查看个人订单 ---");
            System.out.println("--- 3.更新个人信息 ---");
            System.out.println("--- 4.退出 ---");

            String line = scanner.nextLine();
            line = line.trim();
            try {
                if ("1".equalsIgnoreCase(line)) {
                    orderSale(scanner, passenger.getPassengerId() + "");
                } else if ("2".equalsIgnoreCase(line)) {
                    /* 查看个人订单 */
                    orderManager(scanner, passenger.getPassengerId() + "");
                } else if ("3".equalsIgnoreCase(line)) {
                    /* 更新 */
                    System.out.println("--- 请输入乘客信息;(格式如下) ---");
                    passenger.printInputTitle();
                    passenger.printInput();
                    line = scanner.nextLine();
                    line = line.trim();
                    String[] splitArr = line.split(ConstatFinalUtil.SPLIT_INPUT_STR);
                    if (Objects.nonNull(splitArr) && splitArr.length == 5) {
                        passenger.setPassengerIdCardNo(splitArr[0]);
                        passenger.setPassengerPasswd(splitArr[1]);
                        passenger.setPassengerName(splitArr[2]);
                        passenger.setPassengerPhoneNo(splitArr[3]);
                        passenger.setPassengerGender(Integer.parseInt(splitArr[4]));
                        ApiResponse<Object> dbApiResponseInfo = this.usersAction.updateOnePassengerService(passenger);
                        System.out.println("==保存乘客操作;信息:==" + dbApiResponseInfo.getInfo());
                        ConstatFinalUtil.SYS_PRO_MAP.put("users", passenger);
                    } else {
                        System.out.println("--- 您输入数量不正确 ---");
                    }
                } else if ("4".equalsIgnoreCase(line)) {
                    break;
                }
            } catch (Exception e) {
                log.error("操作数据有误,您输入的是:{}", line, e);
            }
        }
    }

    /**
     * 管理员(菜单)
     */
    private void menUnPass(Scanner scanner) {
        while (true) {
            System.out.println("---------------------");
            System.out.println("--- 乘客未登录 ---");
            System.out.println("--- 1.登录 ---");
            System.out.println("--- 2.注册 ---");
            System.out.println("--- b.返回上一步 ---");

            String line = scanner.nextLine();
            line = line.trim();
            try {
                if ("1".equalsIgnoreCase(line)) {
                    /* 登录 */
                    System.out.println("--- 请输入用户名和密码;(格式为:用户名;密码) ---");
                    line = scanner.nextLine();
                    line = line.trim();
                    String[] splitArr = line.split(ConstatFinalUtil.SPLIT_INPUT_STR);
                    if (Objects.nonNull(splitArr) && splitArr.length == 2) {
                        TbPassenger mananger = new TbPassenger();
                        mananger.setPassengerIdCardNo(splitArr[0]);
                        mananger.setPassengerPasswd(splitArr[1]);
                        ApiResponse<Object> dbApiResponseInfo = this.loginAction.passLogin(mananger);
                        System.out.println("==登录操作;信息:==" + dbApiResponseInfo.getInfo());
                        if (dbApiResponseInfo.getCode() == ApiResponseEnum.INFO_LOGIN_SUCCES.getStatus()) {
                            /* 跳转到登录成功的菜单 */
                            menLoginSuccessPass(scanner);
                        }
                    } else {
                        System.out.println("--- 您输入有误 ---");
                    }
                } else if ("2".equalsIgnoreCase(line)) {
                    /* 注册 */
                    System.out.println("--- 请输入用户名和密码;(格式为:用户名;密码;手机号;性别(1:男,2:女);身份证) ---");
                    line = scanner.nextLine();
                    line = line.trim();
                    String[] splitArr = line.split(ConstatFinalUtil.SPLIT_INPUT_STR);
                    if (Objects.nonNull(splitArr) && splitArr.length == 5) {
                        TbPassenger pojo = new TbPassenger();
                        pojo.setPassengerName(splitArr[0]);
                        pojo.setPassengerPasswd(splitArr[1]);
                        pojo.setPassengerPhoneNo(splitArr[2]);
                        pojo.setPassengerGender(Integer.parseInt(splitArr[3]));
                        pojo.setPassengerIdCardNo(splitArr[4]);
                        ApiResponse<Object> dbApiResponseInfo = this.loginAction.passRegister(pojo);
                        System.out.println("==注册操作;信息:==" + dbApiResponseInfo.getInfo());
                    } else {
                        System.out.println("--- 您输入数量不正确 ---");
                    }
                } else if ("b".equalsIgnoreCase(line)) {
                    break;
                }
            } catch (NumberFormatException e) {
                log.error("操作数据有误,您输入的是:{}", line, e);
            }
        }
    }
}
